/*** author: sailing date: 2018/10/23 ***/

<template>
  <div class="HomeContent">
    <div class="demo-list-wrap">
      <ul class="bar-left">
        <li>工单名称:{{ workData.name }}</li>
        <li>创建者:{{ workData.operator }}</li>
        <li>施工者:{{ workData.worker }}</li>
        <li>创建时间:{{ workData.create_time }}</li>
        <li>备注信息:{{ workData.auditor }}</li>
      </ul>
      <ul class="bar-right">
        <mu-button
          class="mu-button"
          color="info"
          style="margin: 1em 1em 0 1em"
          @click="recall"
          >撤销</mu-button
        >
        <mu-button class="mu-button" color="info" style="" @click="nextBtn"
          >完成并提交</mu-button
        >
      </ul>
    </div>
    <mu-divider></mu-divider>
    <div class="demo-list-bottom">
      <ul v-for="info in workData.equipments">
        <mu-button
          class="mu-button"
          color="info"
          style="position: absolute; right: 0.5em"
          @click="cabinetView(info)"
          >上传图片</mu-button
        >
        <input
          @change="fileChange($event)"
          type="file"
          id="upload_file"
          multiple
          style="display: none"
          accept="image/gif,image/jpeg,image/jpg,image/png,image/svg"
        />
        <li>设备名称：{{ info.name }}</li>
        <li>所属机房：{{ info.room_name }}</li>
        <li>所属机柜：{{ info.cabinet_name }}</li>
        <li>起始U位：{{ info.cabinet_pos }}</li>
        <li>状态:{{ info.status }}</li>
        <div v-for="(item, index) in info.images" :key="index" class="allImg">
          <div class="upload_warp_img_right_div_top">
            <div class="upload_warp_img_div_text">
              {{ item.name }}
            </div>
            <img
              src="../assets/del.png"
              class="upload_warp_img_div_del"
              @click="deletCurrImg(info, item)"
            />
          </div>
          <img
            :src="'/equipments/' + item.name"
            style="width: 100%; height: 5rem; display: block"
            class="image"
          />
          <div style="padding: 4px">
            <div class="bottom clearfix">
              <p>上传人:{{ item.user }}</p>
              <p>上传时间:{{ item.time }}</p>
            </div>
          </div>
        </div>
        <mu-divider></mu-divider>
      </ul>
    </div>
    <uploadPanel></uploadPanel>
  </div>
</template>

<script type="text/javascript">
import fetch from "../server/fetch.js";
import tools from "../server/tools";
import motion from "./motion.js";
import eventBus from "../server/eventBus.js";
import uploadPanel from "./Motion.vue";
export default {
  data() {
    return {
      bate: {},
      loading: false,
      workData: [],
      server_id: "",
      tPage: {},
      UUIDinput: "",
    };
  },

  methods: {
    fileChange(el) {
      if (!el.target.files[0].size) return;
      this.fileList(el.target);
      el.target.value = "";
    },
    fileList(fileList) {
      let files = fileList.files;
      for (let i = 0; i < files.length; i++) {
        // 判断是否为文件夹
        if (files[i].type.indexOf("image") > -1) {
          this.submitForm(files[i]);
        } else {
          this.$toast.warning("请上传图片格式");
        }
      }
    },
    deletCurrImg(info, row) {
      var path, obj;
      path = "/equipment/removepicture/";
      obj = {
        id: info.id,
        name: row.name,
      };
      fetch.axiosGet({
        callback: (res) => {
          if (res.code === 1) {
            this.$toast.success(res.message);
            this.reloadEquip(1);
          } else {
            this.$toast.warning(res.message);
          }
        },
        data: obj,
        url: path,
      });
    },
    submitForm(files) {
      var formData, path;
      var that = this;
      path = "/equipment/uploadpicture/?" + this.server_id;
      formData = new FormData();
      formData.append("id", this.server_id);
      formData.append("imgStr", files);
      console.log(files);
      fetch.axiosPostFun({
        data: formData,
        callback: (res) => {
          if (res.code == 1) {
            this.$toast.success(res.message);
            that.reloadEquip(0);
          } else {
            this.$toast.warning(res.message);
            this.dialogUp = true;
          }
          this.imgList = [];
          this.size = 0;
        },
        url: path,
        err: (err) => {
          console.log(err);
        },
      });
    },
    // 撤回
    recall() {
      fetch.axiosGet({
        callback: (res) => {
          if (res.code == 1) {
            this.$toast.success("已撤回");
          } else {
            this.$toast.error(res.message);
          }
        },
        url: "/work_order/recall/",
        data: {
          work_order_id: this.UUIDinput.work_order_id,
        },
      });
    },
    rejectedBtn() {
      fetch.axiosGet({
        callback: (res) => {
          if (res.code == 1) {
            this.$toast.success("已驳回");
          } else {
            this.$toast.error(res.message);
          }
        },
        url: "/work_order/cancel_order_by_uuid/",
        data: {
          uuid: this.UUIDinput.uuid,
        },
      });
    },
    // 提交完成
    nextBtn() { 
      fetch.axiosGet({
        callback: (res) => {
          if (res.code == 1) {
            this.$router.push("/Sleeppage");
            setTimeout(_=>{
              top.postMessage({type: "work_order"},"*");  
            },1500)
          } else {
            this.$toast.error(res.message);
          }
        },
        url: "/work_order/complete_by_uuid/",
        data: {
          uuid: this.UUIDinput.uuid,
          //info: this.infoForm.info // 反馈信息
        },
      });
    },
    cabinetView(info) {
      document.getElementById("upload_file").click();
      this.server_id = info.id;
    },
    reloadEquip(pages) {
      console.log(1212, this.UUIDinput);
      fetch.axiosGet({
        callback: (res) => {
          this.tPage.total = res.data.equipment_total;
          this.tPage.currentPage = pages;
          this.workData = [];
          this.workData = res.data;
        },
        url: "/work_order/get_equipments_by_uuid/",
        data: {
          //uuid: 'e4c72f31-b7fc-4ded-b267-e92d9a6007db',
          uuid: this.UUIDinput.uuid,
          start: pages,
          limit: 50,
        },
      });
    },
  },
  mounted() {
    this.bate = motion;
    this.UUIDinput = tools.getParams();
    this.reloadEquip(0);
  },
  components: {
    uploadPanel,
  },
};
</script>

<style lang="less">
.HomeContent {
  margin-top: 5px;
  width: 100%;
  list-style: none;
  .demo-list-wrap {
    display: flex;
    flex-direction: cloumn;
    .bar-left {
      width: 70%;
      flex: 1;
      li {
        width: 100%;
        list-style: none;
        padding: 0 2rem 0 2rem;
        text-align: start;
      }
    }
    .bar-right {
      width: 30%;
    }
  }
  .demo-list-bottom {
    li {
      width: 100%;
      padding: 0 2rem 0 2rem;
      text-align: start;
    }
  }
  .allImg {
    width: 8rem;
    display: inline-block;
    margin: 1em;
    position: relative;
    .upload_warp_img_right_div_top {
      top: 0;
      width: 100%;
      height: 30px;
      background-color: rgba(0, 0, 0, 0.4);
      line-height: 30px;
      text-align: center;
      color: #fff;
      font-size: 12px;
      text-indent: 4px;
      .image {
        width: 100%;
        display: block;
      }
    }
    .upload_warp_img_div_del {
      position: absolute;
      top: 6px;
      width: 16px;
      right: 4px;
    }

    .upload_warp_img_div_top {
      position: absolute;
      top: 0;
      width: 100%;
      height: 30px;
      background-color: rgba(0, 0, 0, 0.4);
      line-height: 30px;
      text-align: left;
      color: #fff;
      font-size: 12px;
      text-indent: 4px;
    }
  }
  .ulstyle {
    .listyle {
      position: relative;
      .mu-carousel {
        height: 200px;
        margin-top: -20px;
      }
      img {
        min-width: 100%;
        width: 100%;
      }
      .bgtextbg {
        position: absolute;
        background: #000;
        width: 100%;
        bottom: 0;
        height: 40px;
        opacity: 0.5;
      }
      .bgtext {
        position: absolute;
        width: 100%;
        bottom: 0;
        text-align: left;
        color: #fff;
        height: 40px;
        line-height: 40px;
        margin-left: 20px;
      }
    }
    .textList {
      .textItem {
        min-height: 50px;
        line-height: 25px;
        -webkit-box-shadow: 1px 1px 1px #000;
        box-shadow: 0px 2px 4px #dddede;
        margin-top: 10px;
        text-align: left;
        display: -webkit-box;
        margin: 0 auto;
        margin-left: 10px;
        margin-right: 10px;

        .text {
          text-align: left;
        }
        img {
          height: 80px;
          margin-left: 5px;
        }
      }
    }
  }
}
</style>
